//
//  ArrayDataSource.m
//  UI27-ArrayDataSource
//
//  Created by 韩旭 on 16/8/19.
//  Copyright © 2016年 lanou. All rights reserved.
//
#import "ArrayDataSource.h"

//声明初始化参数中对应的属性
@interface ArrayDataSource ()
@property (nonatomic, copy) NSString *reuse;
@property (nonatomic, strong) NSArray *dataSource;
@property (nonatomic, copy) configCell configCell;
@end
@implementation ArrayDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:_reuse];
    id model = _dataSource[indexPath.row];
    //    根据数据源和cell调用block
    self.configCell(cell, model);
    cell.textLabel.text = _dataSource[indexPath.row];
    return cell;
}
- (instancetype)initWithTableViewCellReuse:(NSString *)reuse dataSource:(NSArray *)arr configCell:(configCell)configCell{
    self = [super init];
    if (self) {
        //        属性赋值
        _reuse = reuse;
        _dataSource = arr;
        _configCell = configCell;
    }
    return self;
}
+ (instancetype)arrayDataSourceWithTableViewCellReuse:(NSString *)reuse dataSource:(NSArray *)arr configCell:(configCell)configCell{
    return [[self alloc] initWithTableViewCellReuse:reuse dataSource:arr configCell:configCell];
}
@end